import { myRequest } from '../../api/myRequest'
import { actionsMap } from '../../api/url'

const $RC = 'PageViewManage'
const $RC_actions = actionsMap[$RC]
export default {
  PageViewManage: {
    /**
     * 添加信息
     * @param record
     * @returns {Promise<*>}
     */
    add(record) {
      return myRequest($RC, [{ action: $RC_actions.ADD, data: [record] }])
    },

    /**
     * 删除信息
     * @param id
     * @returns {Promise<*>}
     */
    delete(id) {
      return myRequest($RC, [{ action: $RC_actions.DELETE, id: id }])
    },

    /**
     * 批量删除信息
     * @param ids
     * @returns {Promise<*>}
     */
    batchDelete(filter) {
      return myRequest($RC, [{ action: $RC_actions.BATCH_DELETE, ...filter }])
    },

    /**
     * 批量删除信息
     * @param ids
     * @returns {Promise<*>}
     */
    deleteByIds(ids) {
      return myRequest($RC, [{ action: $RC_actions.DELETE_BY_IDS, ids: ids }])
    },

    /**
     * 更新信息
     * @param record
     * @returns {Promise<*>}
     */
    update(record) {
      // let jsonValue = JSON.stringify(record.value)
      // record['jsonValue'] = jsonValue
      return myRequest($RC, [{ action: $RC_actions.UPDATE, data: [record] }])
    },

    /**
     * 查询列表
     * @param recipient
     * @returns {Promise<*>}
     */
    query(filter) {
      let recipient = [{ action: $RC_actions.QUERY, ...filter }]
      return myRequest($RC, recipient)
    },
    /**
     * 简单查询不包括属性或大字段信息
     * @param filter
     * @returns {Promise<*>}
     */
    queryInfo(filter) {
      let recipient = [{ action: $RC_actions.QUERY_INFO, ...filter }]
      return myRequest($RC, recipient)
    },
    /**
     * 查询列表
     * @param recipient
     * @returns {Promise<*>}
     */
    queryByPage(pageNumber, pageSize, filter) {
      let recipient = [{ action: $RC_actions.QUERY_BY_PAGE, pageNumber: pageNumber, pageSize: pageSize, ...filter }]
      return myRequest($RC, recipient)
    },
    /**
     * 查询列表
     * @param recipient
     * @returns {Promise<*>}
     */
    queryInfoByPage(pageNumber, pageSize, filter) {
      let recipient = [{ action: $RC_actions.QUERY_BY_PAGE, pageNumber: pageNumber, pageSize: pageSize, ...filter }]
      return myRequest($RC, recipient)
    },
  },
}
